﻿App.Router.map(function () {
    this.resource('knowledgedetailtype', { path: '/Knowledge/:knowledgeType_Name' },
        function () {
            // knowledgeDetailType
            this.route('createtype', { path: '/Create' });
            this.route('edittype', { path: '/Edit/:knowledgeDetailType_id' });

            // knowledgeDetail
            this.resource('knowledgedetail', { path: '/:knowledgeDetailType_id' },
                function () {
                    this.route('transtocreatedetail', { path: '#transto' });
                });

            this.route('createdetail', { path: '/:knowledgeDetailType_id/Create' });
            this.route('editdetail', { path: '/Edit/:knowledgeDetail_id' });
            this.route('infodetail', { path: '/Info/:knowledgeDetail_id' });
        });
});

App.Router.reopen({
    //指定路由解析类型
    location: 'history',
    rootURL: '/'
});

App.LoadingRoute = Ember.Route.extend({});

App.ApplicationRoute = Ember.Route.extend({
    setupController: function (controller, model) {
        $.ajax('/Model/KnowledgeDetailType?TypeID=' + Type().id, {
            type: 'GET',
            async: false
        }).then(function (data) {
            App.store.pushMany(App.KnowledgeDetailType, data);
        });
        var models = App.store.filter(App.KnowledgeDetailType, function (knowledgeDetailType) {
            //排除正在创建的实体
            return knowledgeDetailType.currentState.stateName != 'root.loaded.created.uncommitted';
        });
        controller.set('knowledgeDetailTypes', models);
    }
});

App.IndexRoute = Ember.Route.extend({
    //redirect: function () {
    //    this.transitionTo('index');
    //}
});